<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>定时器任务</title>
	<meta name="decorator" content="default"/>
	<%@ include file="/WEB-INF/views/include/bootstrap-table.jsp"%>
</head>

<body>
	<div class="boxcontent clearfix">
		<div class="content clearfix" style="margin: 0;">
			<form id="searchForm"  class="form-search">
				<div class="search-bar">
		          <ul class="clearfix">
		          		 <li>
			              <span>任务名称：</span>
			              <input id="remark" name="remark" class="form-control bootstrap-table-input"/>
						 </li>
			              <li>
			              <span>spring bean名称：</span>
			              <input id="beanName" name="beanName" class="form-control bootstrap-table-input"/>
						 </li>
			              <li>
			              <span>任务状态 ：</span>
			              <select id="status" name="status">
							    <option value="">请选择</option>
								<option value="0" >正常</option>
								<option value="1" > 暂停</option>
							</select>
						 </li>
						</ul>
					<div id="btn_search" class="search-btn">查询</div>
					<script type="text/javascript">
						$(function(){
							$(".search-bar ul li").each(function(){
								var spanWidth = $(this).find("span").width();
								$(this).find(".form-control").width(230-20-spanWidth);	
								$(this).children(".input-append").find(".required").width(230-20-36+1-spanWidth);	
								var barHeight = $(".search-bar").height();
								$(".search-btn").css("line-height", barHeight+"px");
							});
						})
					</script>
				</div>
				
				<div id="toolbar">
				 <shiro:hasPermission name="job:scheduleJob:edit">
					<button type="button" class="btn-custom" onclick="create('job/scheduleJob/scheduleJobForm',false)">新增</button>
				 </shiro:hasPermission>	
				 <shiro:hasPermission name="job:scheduleJob:delete">
					<button type="button" class="btn-custom btndelete" onclick="batchDelete('job/scheduleJob/batchDelete')">批量删除</button>
				 </shiro:hasPermission>
				 <shiro:hasPermission name="job:scheduleJob:edit">
				    <button type="button" class="btn-custom" onclick="batchDoTask('job/scheduleJob/resume','您确定要启动任务吗？')">启动</button>
					<button type="button" class="btn-custom" onclick="batchDoTask('job/scheduleJob/pause','您确定要启动暂停吗？')">暂停</button>
					<button type="button" class="btn-custom" onclick="batchDoTask('job/scheduleJob/run','您确定要启动执行吗？')">执行</button>
					<button type="button" class="btn-custom" onclick="detail('job/scheduleJobLog/scheduleJobLogList','执行日志','')">查看日志</button>
				 </shiro:hasPermission>	
				</div>
			</form>
			
		<div class="tbbox firsttdCenter">
		
	    <table id="table" 
	         data-toggle="table" 
	         data-url="${ctx}/job/scheduleJob/scheduleJobListJson"
	         data-toolbar="#toolbar"
		     data-height="${dataHeight491}" 
		     data-maintain-selected="true" 
		     data-side-pagination="server"
		     data-click-to-select="true" 
		     data-pagination="true" 
		     data-single-select="false"
		     data-id-field="id"
		     data-query-params="doQuery"
		     data-cache="false"
		     data-show-columns="true"
		     data-page-list="${dataPageList}">
		<thead>
			<tr>
		    	<!-- 属性 data-visible="false" 可以隐藏列 -->
		    	<!-- 属性data-sortable="true" 可以列排序 -->
				<th data-checkbox="true"></th>
				<th data-field="id" data-formatter="operationFormatter" class="date-width-150">操作</th>
					   <th data-field="remark">任务名称</th>
					   <th data-field="beanName">spring bean名称</th>
					   <th data-field="methodName">方法名</th>
					   <th data-field="params">参数</th>
					   <th data-field="cronExpression">cron表达式</th>
					   <th data-field="status" data-formatter="statusFormatter" >任务状态</th>
					   <th data-field="updateDate">更新时间</th>
					   <th data-field="remarks">备注信息</th>
			</tr>
		</thead>
	    </table>
	    </div>
	</div>
	
	<script type="text/javascript">
	  var $table = $('#table');
	  $(function () { 
          
	      $("#btn_search").click(function () { 
	              $table.bootstrapTable('refresh'); 
	       }); 
	   }); 
	  
	  //查询函数
	  function doQuery(params) {
		  
        	 var remark = $("#remark").val();
			 if(remark != null && remark !=''){
				params.remark = remark;
			 }
			 
           	 var beanName = $("#beanName").val();
			 if(beanName != null && beanName !=''){
				params.beanName = beanName;
			 }
			 
           	 var status = $("#status").val();
			 if(status != null && status !=''){
				params.status = status;
			 }
			 
		    return params;
	}
	
	/**
	*  操作项  add for lgx  提供查看，修改，删除按钮，如果还有系统按钮，
	*  比如禁用，可在子页面进行自定义函数添加（建议列表操作项按钮不要超过5个）
	*/
	function operationFormatter(value, row){
		
		var params = "id="+value;
		//查看
		var html = '<a href="javascript:void(0);" style="padding-right:5px;" onclick="detail(\'job/scheduleJob/scheduleJobDetail\',\'查看定时器任务信息\',\''+params+'\')">查看</a>';
		//修改
		html = html + '<a href="javascript:void(0);" style="padding-right:5px;" onclick="modify(\'job/scheduleJob/scheduleJobForm\',\'修改定时器任务信息\',\''+params+'\')">修改</a>';
		//删除
		html= html  + '<a href="javascript:void(0);" style="padding-right:5px;" onclick="deleteData(\'job/scheduleJob/deleteAjax\',\'是否删除数据？\',\''+params+'\')">删除</a>';
		//日志
		html =html  + '<a href="javascript:void(0);" style="padding-right:5px;" onclick="detail(\'job/scheduleJobLog/scheduleJobLogList\',\'执行日志\',\''+params+'\')">日志</a>';
		
		return html;
	}  
	
	function statusFormatter(value, row){
		//0：正常   1：暂停
		if(value == "0"){
			return "正常";
		}else{
			return "暂停";
		}
	}

	//
	function batchDoTask(url,title){
		
		var row_date_arr = $table.bootstrapTable('getSelections');
		
		if(row_date_arr.length == 0){
			showTip("请至少选择一条操作数据！", "info", undefined, undefined);
		    return false;
		}
		var param = '';
		
		$.each(row_date_arr,function (index,row){
			var select_id = row.id;
			param = param + select_id +",";
		});
		

		
		//alert(param);
		top.$.jBox.confirm(title,'系统提示',function(v, h, f) {
			if (v == "ok") {
				loadingAndTimeout("正在处理中...",3000);
				
				url = "${ctx}/"+url+"?ids="+param;
                $.ajax({  
                    type:"get",  //提交方式  
                    url:url,//路径
                    dataType:"text",
                    cache:false,
                    success : function(result) {//返回数据根据结果进行相应的处理  
                    	if(result.indexOf('成功') > -1 ){
                    		top.$.jBox.tip(result,'success'); 
                    		$table.bootstrapTable('refresh'); 
                    	}else{
                    		top.$.jBox.tip(result,'error'); 
                    		$table.bootstrapTable('refresh'); 
                    	}
                    },
                    error : function() {
                    	 top.$.jBox.tip('请求异常,操作失败!','error');  
                    }
                });  
			}
		});
	}
	</script>
	
	<jsp:include page="/WEB-INF/views/include/pageJs.jsp" />
</body>

</html>